package top.igotcha;

/**
 * @author Gotcha
 * @date 2021/3/22
 * @describe 双重校验
 */
public class Singleton02 {
    private volatile static Singleton02 singleton = null;
    private Singleton02(){

    }

    public static Singleton02 getInstance() {
        if (singleton==null){
            synchronized (Singleton02.class){
                if (singleton==null){
                    singleton = new Singleton02();
                }
            }
        }
        return singleton;
    }
}
class test02{
    public static void main(String[] args) {
        Singleton02 singleton02a = Singleton02.getInstance();
        Singleton02 singleton02b = Singleton02.getInstance();
        System.out.println(singleton02a.equals(singleton02b));
    }
}
